//
//  BaseWindow.m
//  macapp
//
//  Created by Cocoa on 2020/4/7.
//  Copyright © 2020 Talent. All rights reserved.
//

#import "BaseWindow.h"

@implementation BaseWindow

+(instancetype)windowWithContentViewController:(NSViewController*)contentViewController
{
   if (@available(macOS 10.11, *))
   {
       return [super windowWithContentViewController:contentViewController];
   }
   else //workaround for mac 10.10
   {
       BaseWindow * window = [[self alloc]init];
       window.contentViewController = contentViewController;
       return window;
   }
}

- (instancetype)initWithContentRect:(NSRect)contentRect styleMask:(NSWindowStyleMask)style backing:(NSBackingStoreType)backingStoreType defer:(BOOL)flag {
    if (self = [super initWithContentRect:contentRect styleMask:style backing:backingStoreType defer:flag]) {
        [self setupMakeWindow];
    }
    
    return self;
}

- (void)setupMakeWindow {
//    self.hasShadow = NO;
//    self.opaque = NO;
//    self.titleVisibility = NSWindowTitleHidden;
//    self.titlebarAppearsTransparent = YES;
//    // 设置 window颜色
//    self.backgroundColor = NSColor.clearColor;
//    // 设置点击空白区移动窗体
//    //        self.movableByWindowBackground = YES;
//    self.showsToolbarButton = NO;
//    self.styleMask = NSWindowStyleMaskFullSizeContentView | NSWindowStyleMaskTitled | NSWindowStyleMaskResizable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskClosable;
//    //隐藏zoom按钮
//    [self standardWindowButton:NSWindowZoomButton].hidden = YES;
//    [self center];
}

- (void)setContentView:(__kindof NSView *)contentView {
    contentView.wantsLayer = YES;
    [super setContentView:contentView];
}

- (BOOL)canBecomeKeyWindow {
    return YES;
}

- (BOOL)canBecomeMainWindow {
    return YES;
}

- (void)close {
    [super close];
//    NPYBaseViewController *basevc = (NPYBaseViewController *)self.contentViewController;
//    [_currentWindows removeObject:self];
//    [NSApp stopModal];
//    if (basevc.beforeWindow != nil)
//    {
//        AppDelegate *appDelegate = (AppDelegate *)[NSApplication sharedApplication].delegate;
//        appDelegate.mainWindowController = basevc.beforeWindow.windowController;
//        [basevc.beforeWindow makeKeyWindow];
//    }

}

- (void)didTapClose:(NSButton *)b {
//    [NSApp stopModal];
//    if (![self.windowDelegate respondsToSelector:@selector(didTapWindowClose:)]) return;
//    [self.windowDelegate didTapWindowClose:self];
}

@end
